package com.jse;

import java.lang.reflect.Modifier;
import java.util.Set;

import javax.servlet.ServletContainerInitializer;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.HandlesTypes;

import org.nutz.log.Log;
import org.nutz.log.Logs;

/**
 * 启动
 * 
 * @author Administrator
 *
 */
@HandlesTypes(WebApplicationInitializer.class)
public class JseInitializer implements ServletContainerInitializer {

	Log log = Logs.get();

	@Override
	public void onStartup(Set<Class<?>> webApplicationInitializers, ServletContext sce) throws ServletException {
		if (webApplicationInitializers != null) {
			for (Class<?> webApplicationInitializerClass : webApplicationInitializers) {
				if (!webApplicationInitializerClass.isInterface()
						&& !Modifier.isAbstract(webApplicationInitializerClass.getModifiers())
						&& WebApplicationInitializer.class.isAssignableFrom(webApplicationInitializerClass)) {
					try {
						((WebApplicationInitializer) webApplicationInitializerClass.newInstance()).init(sce);
					} catch (Throwable ex) {
						throw new ServletException("Failed to instantiate webApplicationInitializer class", ex);
					}
				}
			}
		}
	}

}
